// components/bottomHandle/bottomHandle.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isCollect: {
      type: Boolean,
      value: false
    },
    roleType: {
      type: Number,
      value: 1,
    },
    expertData: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isCollection: false,
    role: 1,//当前用户角色
    scanExpert: {},
  },
  observers: {
    'isCollect': function (newValue) {
      this.setData({
        isCollection: newValue
      })
    },
    'roleType': function (newValue) {
      this.setData({
        role: newValue
      })
    },
    'expertData': function (newValue) {
      this.setData({
        scanExpert: newValue
      })
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.setData({
        // isCollection: this.properties.isCollect,
        // role: this.properties.roleType,
        scanExpert: this.properties.expertData
      })

    },
    detached: function () {

    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    wechatShare() {
      this.triggerEvent('wxShare');
    },
    chatAction() {
      this.triggerEvent('chatAction')
    },
    collectAction() {
      this.triggerEvent('collectAction')
    },
    reportAction() {
      this.triggerEvent("reportAction")
    },
    bookingAction() {
      this.triggerEvent("bookingAction")
    },

    //单独的专家咨询
    expertChatAction() {
      if (!app.globalData.isLogin) {
        wx.navigateTo({
          url: '/pages/login/login',
        })
        return;
      }
      // console.log("JJLog:" + JSON.stringify(e));
      let item = this.data.scanExpert;
      let chatData = {
        name: item.name,
        avatar: item.avatar,
        chatUserId: item.openId,
        conversationType: "C2C",
        // expertId: item.id,
        // expertPhone: item.phone || "",
        // expertWeChat: item.wxChat || "",
      }
      app.globalData.chatData = chatData;
      wx.navigateTo({
        url: '/firstPackage/pages/msgModule/chatRoom/chatRoom',
      })
    },

    //单独的专家电话
    expertPhoneAction() {
      let phone = this.data.scanExpert.phone || "";
      if (phone) {
        wx.makePhoneCall({
          phoneNumber: phone,
          fail: err => {

          }
        })
      }
    },
  }
})
